import 'dart:math';

import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: Text("GestureDetector配置"),
      ),
      body: HomeScreen(),
    ),
  ));
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  var _gestureName = "";
  var _height = 200.0;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      //dragStartBehavior: down,
      /*onPanDown: (event)=>print("onPanDown"),
      onPanStart: (event)=>print("onPanStart"),
      onPanUpdate: (event)=>print("onPanUpdate"),
      onPanEnd: (event)=>print("onPanEnd"),
      onPanCancel: ()=>print("onPanCancel"),*/

      onLongPress: () {
        setState(() {
          _gestureName = "Long pressed";
        });
      },

      onDoubleTap: () {
        setState(() {
          _gestureName = "onDoubleTap";
        });
      },
      onTapUp: (event) {
        setState(() {
          _gestureName = "onTapUp";
        });
      },

      onHorizontalDragStart: (event) {
        setState(() {
          _gestureName = "onHorizontalDragStart";
        });
      },
      onHorizontalDragDown: (event) {
        setState(() {
          _gestureName = "onHorizontalDragDown";
        });
      },
      onHorizontalDragCancel: () {
        setState(() {
          _gestureName = "onHorizontalDragCancel";
        });
      },
      onHorizontalDragUpdate: (event) {
        setState(() {
          _gestureName = "onHorizontalDragUpdate";
        });
      },
      onHorizontalDragEnd: (event) {
        setState(() {
          _gestureName = "onHorizontalDragEnd";
        });
      },

      onScaleUpdate: (update) {
        // scale 和 pan 不能共存
        print("scale update${update.scale}");
        print("scale clamp:${update.scale.clamp(0.8, 1.0)}");
        setState(() {
          _height = update.scale.clamp(0.5, 2.0)* 200;
        });
      },

      child: Stack(children: <Widget>[
        Container(
          width: double.infinity,
          height: double.infinity,
          child: Center(child: Text("current:$_gestureName")),
        ),
        Center(
          child: Image.network(
              "http://f.hiphotos.baidu.com/image/h%3D300/sign=d8d48aa8a151f3dedcb2bf64a4eff0ec/4610b912c8fcc3ce863f8b519c45d688d53f20d0.jpg",
              width: double.infinity,
              height: _height),
        ),
      ]),
    );
  }
}
